<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<style>
			.title {
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
			}
			
			.circle {
				position: absolute;
				margin: 52px 45px;
				width: 12px;
				height: 12px;
				background: #fff;
				border-radius: 50%;
				border: 1px solid #2090ff;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="height: 55px;">
			<div style="margin-top: 15px;">
				<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
				<h1 class="mui-title">通知</h1>
				<label class="mui-pull-right" style="margin-top: 4%;font-size:medium; color:#007AFF" onclick="clear_historyMes()">清空</label>
			</div>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view" id="notice" style="display: ;">
			</ul>
		</div>

	</body>
	<script src="../js/mui.min.js"></script>
	<script src="../js/jquery-1.6.2.min.js"></script>
	<script src="../js/urlconfiguration.js"></script>
	<script>
		var user_id = localStorage.getItem("user_id");
		(function($, doc) {
			$.init();
			$.plusReady(function() {
				jQuery.ajax({
					contentType: "application/json",
					type: "get",
					url: url_2 + "front_get_messages.do?jsoncallback=?",
					data: "user_id=" + user_id,
					dataType: "json",
					success: function(data) {
						if(data.list == null || data.list == "") {

							mui.alert("暂无消息");
						} else {
							for(i = 0; i < data.list.length; i++) {
								if(data.list[i].checkstatus == 0) {
									checkstatus = "display:;";
								}
								if(data.list[i].checkstatus == 1) {
									checkstatus = "display:none;";
								}
								jQuery("#notice").append('<li class="mui-table-view-cell " id="' + data.list[i].id + '" >' +
									'<div id="singleMes_delete" class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red">删除</a></div>' +

									'<a onclick="check_notice(' + data.list[i].id + ',' + data.list[i].receiver_type + ')">' +

									'<div class="mui-slider-handle"><span id="point_' + data.list[i].id + '"  style="' + checkstatus + ';color:#DD524D;">●</span>' + data.list[i].message + '</div>' +
									'</a>' + '</li>');
							}
						}
					},
				});
			});
			$('#notice').on('slideleft', '.mui-table-view-cell', function(event) {
				var elem = this;
				var id = this.id;
				var btnArray = ['取消', '确认'];
				mui.confirm('确认删除该条记录？', '警告', btnArray, function(e) {
					if(e.index == 1) {
						var w = plus.nativeUI.showWaiting("正在加载...\n");
						jQuery.ajax({
							contentType: "application/json",
							type: "get",
							url: url_2 + "front_delete_message.do?jsoncallback=?",
							data: "id=" + id,
							dataType: "json",
							success: function(data) {
								//1成功，0失败
								if(data.flag == 1) {
									w.close();
									elem.parentNode.removeChild(elem);
									mui.alert("删除成功！")
								} else {
									w.close();
									mui.alert("删除失败！")
								}
							},
							error: function() {
								w.close();
								alert("网络连接出错失败！")
							}
						})
					}
				});
			});
		})(mui, document);

		function clear_historyMes() {
			var btnArray = ['取消', '确认'];
			mui.confirm('确认删除所有消息？', '警告', btnArray, function(e) {
				if(e.index == 1) {
					var w = plus.nativeUI.showWaiting("正在加载...\n");
					id = 122;
					$.ajax({
						contentType: "application/json",
						type: "get",
						url: url_2 + "front_delete_allmessage.do?jsoncallback=?",
						data: "reciveuser_id=" + user_id,
						dataType: "json",
						success: function(data) {
							//1成功，0失败
							if(data.flag == 1) {
								w.close();
								document.getElementById("notice").style.display = "none";
								mui.alert("删除成功！")
							} else {
								w.close();
								mui.alert("删除失败！")
							}
						},
						error: function() {
							w.close();
							mui.alert("网络连接出错失败！")
						}
					})
				}
			})
		}

		function check_notice(notice_id, receiver_type) {
			var w = plus.nativeUI.showWaiting("正在加载...\n");
			var checkstatus = document.getElementById("point_" + notice_id);
			$.ajax({
				contentType: "application/json",
				type: "get",
				url: url_2 + "front_get_message.do?jsoncallback=?",
				data: "id=" + notice_id,
				dataType: "json",
				success: function(data) {
					w.close();
					if(checkstatus.style.display == "") {
						checkstatus.style.display = "none";
					}
					if(receiver_type == 0) {
						var baseUrl = '../order/getorder.html';
					} else if(receiver_type == 1) {
						var baseUrl = '../order/historyorder.html';
					} else if(receiver_type == 2) {
						mui.alert("请到工长发布列表查看");
						return
					}
					var url = mui.os.plus ? baseUrl : baseUrl;
					mui.openWindow({
						url: url,
					})
				}
			})
		}
	</script>

</html>